Literal Values


This page describes the literal value types supported by Pog.

Overview

A literal value is a constant whose value is known at compile time. For example, the value 10 is an integer literal, but the name of an integer variable is not since its value will be determined at run-time by the assignments made to it.

Literals are distinguished from constants by having no name. Constants are names for literals that may be re-used.

Numeric literals

A decimal integer literal has one of the following forms:
0
dddddd
Where each 'd' is a decimal digit, with the first one nonzero.

For example, 0, 123 and 45600789 are all decimal integer literals. 01 and 00345345 are not.

The literal's value is is its usual value as a decimal number. It has the type int.

A hexadecimal integer literal has one of the following forms:
0xhhh
0Xhhh
Where each 'h' is a hexadecimal digit, which is either a decimal digit or one of the letters A-F. Hexadecimal digits are not case sensitive.

For example, 0xabcd and 0x12EF are hexadecimal integer literals. abcd and 00Xab are not.

The literal's value is its usual value as a hexadecimal (base 16) number. It has the type int.

Hexadecimal numbers are useful for writing sets of flags, since encoding individual binary bits is easy in hexadecimal.

A floating-point literal has one of the forms:
nnn.nnn
nnn.
.nnn
Where each 'n' is a decimal digit.

It may optionally have an exponent suffix which has one of the forms:
e nnn
e -nnn
Where 'e' is the letter e, in upper or lower case, and each 'n' is a decimal digit.

For example, 1.0, .1 and 13.0e-2 are all floating point literals. E10 and 123 are not.

The literal's value is the usual decimal value of the first part, multiplied by 10 to the power of the exponent part, if it is present. It has the type float.

Boolean literals

There are only two boolean literals - the named values true and false. They have the type bool.

Handle literals

There is only one handle literal, the named value none. It does not have a true type, but it is compatible with any handle type.

String literals

String literals have one of the following forms:
""
"ccccccc"
Where each 'c' is an ASCII character other than '"', or an escape sequence.

The string literal is therefore simply a sequence of characters enclosed in double- quotation marks. Within the quotation marks certain characters may have their usual meanings changed using the escape character '\'. This allows non-printing characters to be embedded in strings, for example. The compiler converts escape sequences to the appropriate characters when it parses the string literal.

The following table lists the character escape sequences supported in Pog string literals:
Sequence Meaning
\n New line
\t Horizontal tab
\v Vertical tab
\b Backspace
\r Carriage return
\f Form feed
\a Bell
\\ Literal backslash
\' Literal single-quote mark
\? Literal question mark

Note:

Pog does not support any numeric escape sequences.